<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s"  uri="/struts-tags" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html">
<head>
   	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="X-UA-Compatible" content="chrome=1">
	<title>管理</title>
    <link href="<%=request.getContextPath() %>/css/bootstrap.css" rel="stylesheet" type="text/css">
    <script src="<%=request.getContextPath() %>/js/jquery-2.0.3.min.js" type="text/javascript"></script>
    <script src="<%=request.getContextPath() %>/js/bootstrap.js" type="text/javascript"></script>  
    <!-- 富文本编辑器 -->
	<link href="<%=request.getContextPath() %>/ueditor/themes/default/_css/umeditor.css" type="text/css" rel="stylesheet" />
	<script type="text/javascript" src="<%=request.getContextPath() %>/ueditor/third-party/jquery.min.js"></script>
	<script type="text/javascript" charset="utf-8" src="<%=request.getContextPath() %>/ueditor/umeditor.config.js"></script>
	<script type="text/javascript" charset="utf-8" src="<%=request.getContextPath() %>/ueditor/_examples/editor_api.js"></script>
	<script type="text/javascript" src="<%=request.getContextPath() %>/ueditor/lang/zh-cn/zh-cn.js"></script>
 	<link rel="stylesheet" href="<%=request.getContextPath()%>/css/bootstrapValidator.css"/>
    <script type="text/javascript" src="<%=request.getContextPath()%>/js/bootstrapValidator.js"></script>
<script type="text/javascript">

$(document).ready(function() {
	$('#dataForm')
    .bootstrapValidator({
        message: 'This value is not valid',
        fields: {
            "productIntroduction.name": {
                validators: {
                    notEmpty: {
                        message: '名称不能为空'
                    },
                    regexp: {
                        regexp: /^[a-zA-Z0-9\u4e00-\u9fa5]{2,10}$/,
                        message: '名称由2-10个汉字、字母或数字组成'
                    }
                }
            },
            "": {
                validators: {
                    notEmpty: {
                        message: '内容不能为空'
                    }
                },
                regexp: {
                    regexp: /^[a-zA-Z0-9\u4e00-\u9fa5]{2,10}$/,
                    message: '名称由2-10个汉字、字母或数字组成'
                }
            }
        }
    })
});
	function submitForm(){
		<%-- if(${params=='save'}){
			document.getElementById("dataForm").action="<%=request.getContextPath()%>/product/productIntroduction_updateProductIntroduction";
		}
		if(${params=='add'}){
			document.getElementById("dataForm").action="<%=request.getContextPath()%>/product/productIntroduction_addProductIntroduction";
		}
			document.getElementById("dataForm").submit(); --%>
		var submitUrl;
		if(${params=='save'}){
			submitUrl="<%=request.getContextPath()%>/product/productIntroduction_updateProductIntroduction";
		}
		if(${params=='add'}){
			submitUrl="<%=request.getContextPath()%>/product/productIntroduction_addProductIntroduction";
		}
    	var content = um.getContent();
    	if(content!=undefined&&content.length>0){
			$.ajax({
				url:submitUrl,
				type:'post',
				dataType:'json',
				data:$('#dataForm').serialize(),
				success:function(value){
					alert(value.message);
				}
			});
    	}else{
    		alert("请填写商品详情！");
    	}
	}
</script>
</head>
<body>
<div class="panel panel-primary">
  <div class="panel-heading">商品详情</div>
  <div class="panel-body">
 
  <form id="dataForm" class="form-horizontal" action="" method="post">
  	<input name="method" type="hidden" value="${method }">
  <input name="t.id" type="hidden" value="${t.id }">

  
 <div class="form-group">
    <label class="col-sm-2 control-label">名称：</label>
    
    <div class="col-sm-2">
    	<c:if test="${params=='view' }">
    		<label class="form-control" style="width: 300px">${t.name }</label> 
    	</c:if>
	    <c:if test="${params=='save'||params=='add' }">
	      <input type="text" name="productIntroduction.name" class="form-control"  placeholder="" style="width: 300px"  value="${t.name }" >
	    </c:if>
	    <input name="productIntroduction.id" value="${t.id }" type="hidden">
	</div>
  </div>
<c:if test="${params=='view' }">
 <div class="form-group">
    <label for="input_creationTime" class="col-sm-2 control-label">创建时间：</label>
    <div class="col-sm-2">
    	<label class="form-control" style="width: 300px"><fmt:formatDate value="${t.creationTime }" pattern="yyyy-MM-dd HH:mm:ss"/></label>
    </div>
  </div>
 <div class="form-group">
    <label for="input_updateTime" class="col-sm-2 control-label">修改时间：</label>
    <div class="col-sm-2">
      <label class="form-control" style="width: 300px"><fmt:formatDate value="${t.updateTime }" pattern="yyyy-MM-dd HH:mm:ss"/></label>
    </div>
  </div>
 <div class="form-group">
    <label class="col-sm-2 control-label">创建人：</label>
    <div class="col-sm-2">
    <label class="form-control" style="width: 300px">${t.creator.username }</label>
    </div>
  </div>
 <div class="form-group">
    <label class="col-sm-2 control-label">修改人：</label>
    <div class="col-sm-2">
    <label class="form-control" style="width: 300px">${t.updater.username }</label>
    </div>
  </div>
</c:if>

 <div class="form-group">
   	<label class="col-sm-2 control-label">内容：</label>
    <div class="col-sm-2">
    <input type="hidden" id="contentId" name="contentId">
    <c:if test="${params=='view' }">
    	${t.content }
    </c:if>
    <c:if test="${params=='save'||params=='add' }">
    <script type="text/plain" id="myEditor" name="productIntroduction.content" style="width:700px;">${t.content}</script>
						<script type="text/javascript">
						    //实例化编辑器
						    var um = UM.getEditor('myEditor',{
						    	toolbar:[
						    	            'source | undo redo | bold italic underline strikethrough | superscript subscript | forecolor backcolor | removeformat |',
						    	            'insertorderedlist insertunorderedlist | selectall cleardoc paragraph | fontfamily fontsize' ,
						    	            '| justifyleft justifycenter justifyright justifyjustify |',
						    	            ' emotion | horizontal print preview fullscreen', 'drafts', 'formula'
						    	        ]});
						</script>
    </c:if>
    </div>
  </div>



  <div class="form-group">
   <div class="col-sm-offset-5 col-sm-5">
	      <c:if test="${params=='save'||params=='add' }"><button id="submitBtn" onclick="submitForm()" type="button" class="btn btn-default">提交</button></c:if>
      <button type="button" onclick="history.go(-1)" class="btn btn-default">返回</button>
    </div>
  </div>
</form>
  </div>
  
</div>

</body>
</html>
